package com.fingard.dsp.bank.directConfig;

import java.util.ArrayList;
import java.util.HashMap;

import com.fingard.xml.XElement;

public class NotifySet {

	public String notifyType;
	public String notifyHost;
	public String notifyVirtualHost;
	public String notifyQueueName;
	public String notifyUsername;
	public String notifyPassword;
	
	private HashMap<String,String> notifyQueueNameMap;
	
	public void fromXElement(XElement p_xe) throws Exception{
		notifyType = p_xe.getSingleTextNotNull("notifyType");
		notifyHost = p_xe.getSingleTextNotNull("notifyHost");
		notifyVirtualHost = p_xe.getSingleTextNotNull("notifyVirtualHost");
		notifyQueueName = p_xe.getSingleTextNotNull("notifyQueueName");
		notifyUsername = p_xe.getSingleTextNotNull("notifyUsername");
		notifyPassword = p_xe.getSingleTextNotNull("notifyPassword");
		
		notifyQueueNameMap = getForMap(p_xe, "notifyQueueName");
	}
	
	public String getNotifyQueueName(String p_for){
		if(notifyQueueNameMap != null && notifyQueueNameMap.containsKey(p_for)){
			return notifyQueueNameMap.get(p_for);
		}
		return null;
	}
	
	private HashMap<String,String> getForMap(XElement p_xe, String p_nodeName){
		HashMap<String,String> retMap = null;
		ArrayList<XElement> listXe = p_xe.getChildList(p_nodeName);
		if(listXe != null && listXe.size() > 0){
			retMap = new HashMap<String,String>();
			for(int i=0;i<listXe.size();i++){
				String eachFor = listXe.get(i).getAttrValue("for");
				if(eachFor == null){
					eachFor = "";
				}
				retMap.put(eachFor, listXe.get(i).innerText);
			}
		}
		return retMap;
	}
	
	public NotifySet clone(){
		NotifySet notifySet = new NotifySet();
		
		notifySet.notifyType = this.notifyType;
		notifySet.notifyHost = this.notifyHost;
		notifySet.notifyVirtualHost = this.notifyVirtualHost;
		notifySet.notifyQueueName = this.notifyQueueName;
		notifySet.notifyUsername = this.notifyUsername;
		notifySet.notifyPassword = this.notifyPassword;
		
		return notifySet;
	}
}
